<?php
// +----------------------------------------------------------------------
// | [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Author < 931274989@qq.com >
// +----------------------------------------------------------------------
// | Explain 洗车
// +----------------------------------------------------------------------
namespace app\ymkj\controller;

use app\model\Order as orderModel;
use think\facade\Session;
use think\Controller;
use think\Db;
 
class Xiche extends Controller
{
  public function index()
  {
    $data = request()->param();
    $xiche = Db::name('xiche')->where('id','=',$data['xid'])->find();
    $this->assign('xiche',$xiche);
    return view();
  }

  public function xiche()
  {
    $data = request()->param();
    $order = new orderModel();
    $jine = Db::name('xiche')->where('id','=',$data['xid'])->value($data['xinghao']);
    $user = Session::get('wewhat_user');
    $createOrder = $order->save([
      'openid' => $user['openid'],
      'type' => 'xiche',
      'jine' => $jine,
      'name' => '会员洗车',
      'shop_id' => $data['xid'],
      'xinghao_id' => $data['xinghao'],
    ]);
    if( $createOrder ){
      return redirect('Buy/index',array('order_id'=>$order->id));
    }
    else {
      $this->error('下单失败');
    }

  }
}
?>